<?php
require_once 'BaseController.php';

/**
 * 【PC版】物件一覧 コントローラ
 */
class Renew_ListController extends Renew_BaseController
{

    /**
     * メインアクション
     */
    public function indexAction()
    {
        $params = $this->getParameters();
        $this->convertForCustomTag($params);
        // $params = $this->addCodesToParams2($params,$code,'PrefCd','CityCd');

        $area = $params['Area'];
        $code = $params['Code'];
        $page = $params['page'];
        $page = ($page == NULL || $page == '') ? 1 : intval($page);
        if ($page == 0) $page = 1;
        $page_size = $params['page_size'] = 5;
        $sort_type = $params['sort_type'] = 'sort0';

        $this->getPrefData($code);

        $chous = $params['TownCd'];

        // kodawariIDをオーバーライド
        if (array_key_exists('KodawariId', $params))
        {
            if ($params['KodawariId'] == "apart")
                $params['syubetu1'] = "on";
            else if ($params['KodawariId'] == "mansion")
                $params['syubetu2'] = "on";
            else if ($params['KodawariId'] == "kodate") $params['syubetu3'] = "on";
        }

        $params = $this->makeMainParams($params, $area, $code, $chous);
        $params = $this->makeLeftPainParams($params);

        // ★★★地区変更（地域検索）
        if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_JYUSYO)
        {
            $this->makeCityModalData($params);
        }
        // ★★★地区変更（地域検索）
        // ★★★路線変更、駅選択のデータ準備
        if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_ENSENEKI)
        {
            $this->makeRosenModalData($params);
        }
        // ★★★路線変更、駅選択のデータ準備

        // 2014.11.02 t_kumagaink add
        $params['target_0'] = $code;
        $params['search_type'] = $area;

        $this->makeTemplateParams($params, $page, $page_size, $sort_type);

        // 物件の表示方
        // NULLもしく0->リスト
        // 1: ピッチャー
        // 2: マップ
        $listtype = $params['listtype'];
        if (!isset($listtype) || $listtype == '' || $listtype == '0')
        {
            $this->makeSeoParams($params);
        }

        // ★★★建物、物件詳細URL
        $this->_data['URL'] = 'b';
        // ★★★建物、物件詳細URL

        $this->displayBody2('result');
    }

    public function postAction()
    {
        $params = $this->getParameters();

        $this->_data['maptarget'] = $params['maptarget']; // マップビュー
        $this->convertForCustomTag($params);
        $cat = $params['search_type'];
        $page = $params['page'];
        $page = ($page == NULL || $page == '') ? 1 : intval($page);
        if ($page == 0) $page = 1;

        $page_size = $params['page_size'];
        if (!$page_size) $page_size = 5;

        $sort_type = $params['sort_type'];
        if (!$sort_type) $sort_type = 'sort0';

        // ショップから遷移する→SrhKbn=Apm_Config_Search::SRHKBN_TENPOBUKKEN
        if ($cat == 'shop')
        {
            $params['SrhKbn'] = Apm_Config_Search::SRHKBN_TENPOBUKKEN;
        }

        // こだわり
        if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_KODAWARI)
        {
            if ($params['target_0'])
            {
                $this->getPrefData($params['target_0']);
            }
            else
            {
                $this->getPrefData($params['PrefCd'][0] . "-" . $params['CityCd'][0]);
            }
        }
        // ショップから飛ぶじゃない
        else if ($params['SrhKbn'] != Apm_Config_Search::SRHKBN_TENPOBUKKEN)
        {
            // $this->getPrefData($params['target_0']);
            if ($params['target_0'])
            {
                $this->getPrefData($params['target_0']);
            }
            else
            {
                $this->getPrefData($params['PrefCd'][0] . "-" . $params['CityCd'][0]);
            }
        }
        // ショップとバス
        else if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_TENPOBUKKEN)
        {
            if (!isset($params['shopCd']) || empty($params['shopCd']))
            {
                $params['shopCd'] = $params['target_0'];
            }
        }

        // kodawariIDをオーバーライド
        if (array_key_exists('KodawariId', $params))
        {
            if ($params['KodawariId'] == "apart")
                $params['syubetu1'] = "on";
            else if ($params['KodawariId'] == "mansion")
                $params['syubetu2'] = "on";
            else if ($params['KodawariId'] == "kodate") $params['syubetu3'] = "on";
        }

        $codes = $this->extractParams($params, 'target_');
        $chous = $this->extractParams($params, 'targetchou_');
        $params = $this->makeMainParams($params, $cat, $codes, $chous);

        $params = $this->makeLeftPainParams($params);

        if ($params['mode'] === 'json')
        {
            $this->getmap($params);
        }

        // ★★★地区変更（地域検索）
        if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_JYUSYO)
        {
            $this->makeCityModalData($params);
        }
        // ★★★地区変更（地域検索）

        // ★★★路線変更、駅選択のデータ準備
        if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_ENSENEKI)
        {
            $this->makeRosenModalData($params);
        }

        $this->makeTemplateParams($params, $page, $page_size, $sort_type);
        // 物件の表示方
        // NULLもしく0->リスト
        // 1: ピッチャー
        // 2: マップ
        // ショップじゃない場合だけ
        $listtype = $params['listtype'];
        if ($params['SrhKbn'] != Apm_Config_Search::SRHKBN_TENPOBUKKEN && (!isset($listtype) || $listtype == '' || $listtype == '0'))
        {
            $this->makeSeoParams($params);
        }

        // ★★★建物、物件詳細URL
        $this->_data['URL'] = '/article/b';
        $this->_data['DETAILURL'] = '/detail/';
        // ★★★建物、物件詳細URL

        $this->displayBody2('result');
    }

    public function xAction()
    {
        $params = $this->getParameters();
        $this->convertForCustomTag($params);

        $page = 1;
        $page_size = $params['page_size'] = 5;
        $sort_type = $params['sort_type'] = 'sort0';

        $this->getPrefData($params['PrefCd'][0]);

        $params = $this->makeMainParams($params);
        $params = $this->makeLeftPainParams($params);
        $this->makeTemplateParams($params, $page, $page_size, $sort_type);

        // 物件の表示方
        // NULLもしく0->リスト
        // 1: ピッチャー
        // 2: マップ
        $listtype = $params['listtype'];
        if (!isset($listtype) || $listtype == '' || $listtype == '0')
        {
            $this->makeSeoParams($params);
        }
        $this->displayBody2('result');
    }

    private function makeMainParams($params, $cat, $code, $chous = null)
    {

        // 物件の表示方
        // NULLもしく0->リスト
        // 1: ピッチャー
        // 2: マップ
        $listtype = $params['listtype'];

        // 地域検索
        if ($cat == 'area')
        {
            // ショップパラメータ
            $shopparams['SrhKbn'] = Apm_Config_Search::SRHKBN_JYUSYO;
            $shopparams = $this->addCodesToParams2($params, $code, 'PrefCd', 'CityCd');
            $shopmodel = new Shop_Model_ListForCity();
            // ショップパラメータ

            $params['SrhKbn'] = Apm_Config_Search::SRHKBN_JYUSYO;
            $params = $this->addCodesToParams2($params, $code, 'PrefCd', 'CityCd');
            $model1 = new Search_Model_Selareasearch();
            $this->_data['Mapping_pref'] = $model1->getPrefNameByPrefCd($params);

            $model2 = new Search_Model_Selcyo();
            $Mapping_city = array();
            $Mapping_city = $model2->getShikucyosonNameByShikucyosonCd($params);

            // 町名
            if (isset($chous) && $chous != null && sizeof($chous) > 0)
            {
                $params['TownCd'] = $chous;
                $chou_list = $model2->getCyoNameByCyoCd($params);

                // 市区町村と町名をマージする
                $Mapping_chou = array();
                foreach ($Mapping_city as $city)
                { // 市区町村ループ

                    $city['CHOU'] = array();
                    foreach ($chou_list as $chou)
                    { // 町ループ
                        if ($city['M01_SHIKUCHOUSON_CD'] == $chou['M01_SHIKUCHOUSON_CD'])
                        {
                            $city['ISCHOU'] = 1;
                            $city['CHOU'][] = $chou;
                        }
                    }
                    $Mapping_chou[] = $city;
                }
                $this->_data['Mapping_city'] = $Mapping_chou;
            }
            else
            {
                $this->_data['Mapping_city'] = $Mapping_city;
            }

            if (!isset($listtype) || $listtype == '' || $listtype == '0')
            {
                // 最初の市区の町名を取得
                $citymodel = new Search_Model_Selareasearch();
                $city_data = array();
                if (is_array($code))
                {
                    $cityParams['cityCds'] = "'" . substr($code[0], 5) . "'";
                }
                else
                {
                    $cityParams['cityCds'] = "'" . substr($code, 5) . "'";
                }
                $cityParams['prefCd'] = $params['PrefCd'][0];
                $city_data = $citymodel->getChouList($cityParams);

                $this->_data['selCity'] = $city_data;
                // 最初の市区の町名を取得
            }
        }
        // 路線検索
        else if ($cat == 'line')
        {
            // ショップパラメータ
            $shopparams['SrhKbn'] = Apm_Config_Search::SRHKBN_ENSENEKI;
            if (is_array($code))
            {
                foreach ($code as $c)
                {
                    $items = split('-', $c);
                    if (!array_key_exists($items[0], $shopparams['PrefCd']))
                    {
                        $shopparams['PrefCd'][] = $items[0];
                    }
                    $raicd = substr($items[1], 0, 4);
                    if (!array_key_exists($raicd, $shopparams['RailCd']))
                    {
                        $shopparams['RailCd'][] = $raicd;
                    }
                }
            }
            else
            {
                $items = split('-', $code);
                $shopparams['PrefCd'][] = $items[0];
                $shopparams['RailCd'][] = substr($items[1], 0, 4);
            }

            $shopmodel = new Shop_Model_ListForRail();
            // ショップパラメータ

            $params['SrhKbn'] = Apm_Config_Search::SRHKBN_ENSENEKI;
            $params = $this->addCodesToParams2($params, $code, 'PrefCd', 'StCd');
            $params = $this->makeRailCodeParams($params, 'StCd');

            $model1 = new Search_Model_Selareasearch();
            $this->_data['Mapping_pref'] = $model1->getPrefNameByPrefCd($params);

            $model2 = new Search_Model_Selensen();
            $this->_data['Mapping_ensen'] = $model2->getRailNameByRailCd($params);

            $model3 = new Search_Model_Seleki();
            $this->_data['Mapping_eki'] = $model3->getStNameByStCd($params);

            // リストモードだけ
            if (!isset($listtype) || $listtype == '' || $listtype == '0')
            {
                // 近隣駅に変更する
                // 一番小さい駅CDで前後2件
                // 20150124-SEOコメント
                // $ekimodel = new Search_Model_Seleki();
                // $stList = array();
                // $nearList = array();

                // foreach($params['StCd'] as $stion){
                // $ekiCd = $stion;
                // $ensenCd = substr($ekiCd, 0, 4);
                // if(in_array($ensenCd, $stList)) continue;
                // $stList[] = $ensenCd;

                // $ekidata = $ekimodel->getNearEki($ensenCd, $ekiCd);
                // $showeki = array();
                // $showeki['ENSEN_NAME'] = $ekidata[0]['ENSEN_NAME'];
                // $showeki['ENSEN_CD'] = $ensenCd;
                // $showeki['DATA'] = array();
                // foreach($ekidata as $eki){
                // $showeki['DATA'][] = array(
                // 'PREFNAME' => $this->getPrefName($eki['TODOUFUKEN_CD']),
                // 'EKI_CD' => $eki['EKI_CD'],
                // 'EKI_NAME' => $eki['EKI_NAME'],
                // 'CURRENT' => ($eki['EKI_CD'] == $ekiCd ? true : false)
                // );
                // }
                // $nearList[] = $showeki;
                // }
                // $this->_data['NEAREKI'] = $nearList;
                // 20150124-SEOコメント
                // 近隣駅に変更する
            }
        }
        else if ($cat == 'shop')
        {
            $model_shop = new Shop_Model_Detail();
            $dbParams = array();
            $dbParams['ShopCd'] = $params['shopCd'];
            $shop = $model_shop->getList($dbParams);
            $this->_data['Mapping_shop'] = $shop;
        }

        // 11番ショップ検索
        if ($cat != 'shop' && isset($shopmodel))
        {
            $shopdata = $shopmodel->getList($shopparams);

            __log_debug_array($shopparams);

            $baseurl = $this->_config['apm']['baseurl'] . 'shop/shopdtl';
            $tenpoimageurl = $this->_config['apm']['apl']['imagesvurl'] . 'fs/tenpoimg/';
            if ($cat == 'area')
            {
                $shopdata = $shopmodel->convertList($shopdata, $tenpoimageurl, $url, $shopparams);
            }
            else
            {
                $shopdata = $shopmodel->convertListForBuken($shopdata, $tenpoimageurl, $url, $shopparams);
            }
            $this->_data['MappingShop'] = $shopdata;
            $this->_data['MappingShop_tenpoimageurl'] = $tenpoimageurl;
        }
        // 11番ショップ検索

        // リストモードだけ
        if (!isset($listtype) || $listtype == '' || $listtype == '0')
        {
            // 都道府県のすべて駅、市区
            // 20150124-SEOコメント
            // $model1 = new Search_Model_Selareasearch();
            // $prefArea = $model1->getShikuchousonOfPref($params['PrefCd'][0]);
            // $this->_data['PREFAREA'] = $prefArea;

            // $ekimodel = new Search_Model_Seleki();
            // $prefEki = $ekimodel->getPrefEki($params['PrefCd'][0]);
            // $this->_data['PREFEKI'] = $prefEki;
            // 都道府県のすべて駅、市区
            // 20150124-SEOコメント
        }

        // リスト
        if (!isset($listtype) || $listtype == '0' || $listtype == '')
        {
            $this->_data['Show_list'] = true;
            $this->_footer_data['Show_list'] = true;
        }
        // 画像リスト
        else if ($listtype == '1')
        {
            $this->_data['Show_picture'] = true;
            $this->_footer_data['Show_picture'] = true;
        }
        // マップリスト
        else if ($listtype == '2')
        {
            $this->_data['Show_map'] = true;
            $this->_footer_data['Show_map'] = true;
        }
        $this->_data['listtype'] = $params['listtype'];

        if (array_key_exists('KodawariId', $params))
        {
            switch ($params['KodawariId'])
            {
                case 1:
                    $params['kodawari10'] = 'on';
                    break;
                case 2:
                    $params['built'] = 1;
                    break;
                case 3:
                    // todo:安心セキュリティ
                    break;
                case 4:
                    $params['kodawari112'] = 'on';
                    break;
                case 5:
                    $params['kodawari62'] = 'on';
                    break;
                case 6:
                    $params['kodawari7'] = 'on';
                    break;
                case 7:
                    $params['kodawari11'] = 'on';
                    break;
                case 8:
                    // todo: パノラマ画像あり(SQLで落ちる)
                    $params['kodawari2'] = 'on';
                    break;
                case 9:
                    $params['ekitoho'] = 5;
                    break;
                case 10:
                    $params['kodawari65'] = 'on';
                    break;
                case 11:
                    $params['kodawari63'] = 'on';
                    break;
                case 12:
                    // todo: 3D間取り
                    break;
                case 13:
                    $params['kodawari19'] = 'on';
                    break;
                case 14:
                    // todo: 仲介手数料無料
                    break;
                case 15:
                    $params['kodawari39'] = 'on';
                    break;
                case 16:
                    $params['kodawari9'] = 'on';
                    break;
                case 17:
                    $params['kodawari15'] = 'on';
                    break;
                case 18:
                    $params['kodawari94'] = 'on';
                    break;
                case 19:
                    $params['syubetu3'] = 'on';
                    break;
                case 20:
                    $params['kodawari12'] = 'on';
                    break;
                case 21:
                    $params['kodawari95'] = 'on';
                    break;
                case 22:
                    $params['kodawari81'] = 'on';
                    break;
                case 23:
                    $params['kodawari87'] = 'on';
                    break;
                case 24:
                    $params['kodawari33'] = 'on';
                    break;
                case 25:
                    $params['kodawari112'] = 'on';
                    break;
                case 26:
                    $params['kodawari73'] = 'on';
                    break;
                case 27:
                    $params['kodawari96'] = 'on'; // サンルーム
                    break;
                case 28:
                    $params['kodawari77'] = 'on';
                    break;
                case 29:
                    $params['kodawari8'] = 'on';
                    break;
                case 30:
                    $params['kodawari93'] = 'on';
                    break;
                case 31:
                    $params['kodawari101'] = 'on';
                    break;
                case 32:
                    $params['kodawari44'] = 'on';
                    break;
                case 33:
                    $params['kodawari90'] = 'on';
                    break;
                case 34:
                    $params['kodawari32'] = 'on';
                    break;
                case 35:
                    $params['kodawari61'] = 'on';
                    break;
                case 36:
                    $params['kodawari18'] = 'on';
                    break;
                case 37:
                    $params['syubetu3'] = 'on';
                    break;
                case 38:
                    // todo: 支援住宅(ルーティング失敗)
                    break;
                case 39:
                    // todo: 支援住宅(ルーティング失敗)
                    break;
                case 40:
                    $params['shikikin_nashi'] = 'on';
                    $params['reikin_nashi'] = 'on';
                    break;
                case 41:
                    $params['madori10'] = 'on';
                    break;
            }
        }

        $params['SORT_COLUMN'] = 'T03_YACHIN_KANRI_KYOEKI_SUM';
        $params['SORT_ORDER'] = 'ASC';

        return $params;
    }

    private function makeTemplateParams($params, $page, $page_size, $sort_type)
    {
        $this->getBukkenList($params, $page, $page_size, $sort_type);

        $meta_data = Apm_Bukkenurl::setCommonMeta($params['SrhKbn'], $params, $this->_data['research_data'], true);

        $this->_data['Mapping_page_title'] = $meta_data['new_page_title'];

        // 複数駅をまとめる
        // $valsplit = explode(' ', $meta_data['new_page_title']);
        if ($params['SrhKbn'] != Apm_Config_Search::SRHKBN_TENPOBUKKEN)
        {
            // $ekis = [];

            // $count = sizeof($valsplit);
            // for($i = 0 ; $i < $count - 1; $i++){
            // if(!in_array($valsplit[$i], $ekis)){
            // $ekis[] = $valsplit[$i];
            // }
            // }
            // //最後の駅
            // $vals = explode('の', $valsplit[$count-1]);
            // if(!in_array($vals[0], $ekis)){
            // $ekis[] = $vals[0];
            // }
            $name = '';
            $unit = '市区';
            $size = 0;
            if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_ENSENEKI)
            {
                $name = $this->_data["Mapping_eki"][0]['M03_EKI_ALIAS'];
                $unit = '駅';
                $size = sizeof($this->_data["Mapping_eki"]); // 駅数
            }
            else
            {
                $hasChou = false; // 町検索あり
                $shiNoChou = false; // 市区だけ
                foreach ($this->_data['Mapping_city'] as $shi)
                {
                    if (isset($shi['CHOU']) && $shi['ISCHOU'] == 1)
                    {
                        if ($name == '') $name = $shi['CHOU'][0]['M01_CHOUMEI'];
                        $hasChou = true;
                        $size += sizeof($shi['CHOU']); // 町でカウントアップ
                    }
                    else
                    {
                        if ($name == '') $name = $shi['M01_SHIKUCHOUSON'];
                        $shiNoChou = true;
                        $size += 1;
                    }
                }
                if ($hasChou && !$shiNoChou)
                    $unit = '町村'; // 町だけ検索
                else if ($hasChou && $shiNoChou)
                    $unit = '市区町村'; // 市区町村混ざって検索
                else '市区'; // 市区だけ検索
            }

            if ($size == 1)
            {
                $this->_data['H1_title'] = $name . 'の賃貸情報';
            }
            else
            {
                $this->_data['H1_title'] = $name . 'など' . $size . $unit . 'の賃貸情報';
            }
        }
        else
        {
            $this->_data['H1_title'] = $this->_data['Mapping_page_title'];
        }

        $this->_data['Mapping_params'] = $params;
        // $this->_data['Mapping_kodawari'] = '';
        // 左ペイン表示用にコピー
        // foreach ($this->_data['Mapping_city'] as $key => $val) {
        // $this->_data['disp_Mapping_city'][$key] = $val;
        // }
        // メタタグなどの対応
        if ($meta_data['AREA_FULL'])
        {
            // $this->_data['Mapping_city'][0]['M01_SHIKUCHOUSON'] = $meta_data['AREA_FULL'];
        }
        // if ($meta_data['KODAWARI']) {
        // if ($this->_data['Mapping_kodawari']) $this->_data['Mapping_kodawari'] .= ' ';
        // $this->_data['Mapping_kodawari'] .= $meta_data['KODAWARI'];
        // }
    }

    private function makeLeftPainParams($params)
    {
        $model1 = new Search_Model_Campaignsearch();
        $this->_data['campaign'] = $model1->getCampaignsearch();
        $model1->convertData($params, $this->_data);

        $model2 = new Search_Model_Basicjyoken();
        $this->_data['basic'] = $model2->setChecked($params);

        $model3 = new Search_Model_Kodawarijyoken();
        $this->_data['kodawari'] = $model3->getKodawariJyoken($params);
        $model3->convertKodawariData($params, $this->_data);

        return $params;
    }

    private function getBukkenList($params, $page, $page_size, $sort_type)
    {
        // マップビュー
        $map_list = ($params['listtype'] == '2');
        // ピクチャビュー
        $picture_list = ($params['listtype'] == '1');

        $pager_from = ($page - 1) * $page_size;
        $pager_to = $pager_from + $page_size - 1;

        $model = new Renew_Model_BukkenList();
        $model_conv = new Rstobi_Model_Converte();
        $model_common = new Rstobi_Model_Common();

        $tmp = array();
        $where = '';
        $where .= ' ' . $model_common->getKihonWhere($params, $tmp);
        $where .= ' ' . $model_common->getKodawariWhere($params, $tmp);

        $order = 'min_chinryo';
        $suborder = ',T03.T03_DAIHYO_TATEMONO_CD';
        switch ($sort_type)
        {
            case 'sort0': // お勧め→建物新着、物件階
                          // $order = 'min_chinryo';
                $order = 'max_touroku desc';
                $suborder .= ',lpad(T03.T03_KAI,5)';
                break;
            case 'sort1': // 建物：新着順、物件：新着順
                $order = 'max_touroku desc';
                $suborder .= ',T03.T03_KOUSHINBI DESC';
                break;
            case 'sort2': // 建物：最安値の含まれる建物、物件：賃料の低い順
                $order = 'min_chinryo';
                $suborder .= ',T03.T03_YACHIN_KANRI_KYOEKI_SUM';
                break;
            case 'sort3': // 建物：最高値の含まれる建物、物件：賃料の高い順
                $order = 'max_chinryo desc';
                $suborder .= ',T03.T03_YACHIN_KANRI_KYOEKI_SUM DESC';
                break;
            case 'sort4':
                $order = 'max_senyuu_menseki desc';
                $suborder .= ',T03.T03_SENYUU_MENSEKI DESC';
                break;
            case 'sort5': // 建物：築年数の新しい順、物件：階数順
                $order = 'max_tiku_nensu';
                $suborder .= ',lpad(T03.T03_KAI,5)';
                break;
        }

        $from = $model_common->getCampFrom($params);

        $dbParams = array();
        foreach ($tmp as $key => $val)
        {
            $dbParams[':' . $key] = $val;
        }

        $prefCds = "";
        $c = 0;
        foreach ($params['PrefCd'] as $cd)
        {
            $key = ":PrefCd_" . $c;
            if ($c > 0) $prefCds .= " , ";
            $prefCds .= $key;
            $dbParams[$key] = $cd;
            $c++;
        }

        // 市区町村検索
        if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_JYUSYO || $params['SrhKbn'] == Apm_Config_Search::SRHKBN_KODAWARI)
        {
            // 町検索があれば→検索する
            $cities = array();
            $chous = array();
            if (isset($params['TownCd']))
            {
                foreach ($params['TownCd'] as $val)
                {
                    $city = substr($val, 0, 5);
                    if (!in_array($city, $cities)) $cities[] = $city;
                    $chous[] = substr($val, 2);
                }
            }
            // 町検索があれば→検索する

            $cityCds = "";
            $c = 0;
            foreach ($params['CityCd'] as $cd)
            {
                if (!in_array($cd, $cities))
                { // 町からのぞく
                    $key = ":CityCd_" . $c;
                    if ($c > 0) $cityCds .= " , ";
                    $cityCds .= $key;
                    $dbParams[$key] = substr($cd, 2);
                    $c++;
                }
            }

            $data = $model->getCountForArea($prefCds, $cityCds, $chous, $from, $where, $dbParams, $picture_list);

            // 物件件数
            $bukenParams = $dbParams;
            $bukenParams['favirote'] = true;
            $bukendata = $model->getCountForArea($prefCds, $cityCds, $chous, $from, $where, $bukenParams);
            // 物件件数
        }
        // 路線検索
        else if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_ENSENEKI)
        {
            $stCds = "";
            $c = 0;
            foreach ($params['StCd'] as $cd)
            {
                $key = ":StCd_" . $c;
                if ($c > 0) $stCds .= " , ";
                $stCds .= $key;
                $dbParams[$key] = $cd;
                $c++;
            }
            $data = $model->getCountForLine($prefCds, $stCds, $from, $where, $dbParams, $picture_list);
            // 物件件数
            $bukenParams = $dbParams;
            $bukenParams['favirote'] = true;
            $bukendata = $model->getCountForLine($prefCds, $stCds, $from, $where, $bukenParams);
            // 物件件数
        }
        // 店舗物件検索
        else if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_TENPOBUKKEN)
        {
            $data = $model->getCountForShop($params['shopCd'], $from, $where, $dbParams);

            // 物件件数
            $bukenParams = $dbParams;
            $bukenParams['favirote'] = true;
            $bukendata = $model->getCountForShop($params['shopCd'], $from, $where, $bukenParams);
            // 物件件数
        }

        $count = $data['TATEMONO_COUNT'];
        $this->_data['tatemono_count'] = $bukendata['TATEMONO_COUNT']; // $count;

        $num_pages = (int) ceil($count / $page_size);
        $this->_data['num_pages'] = $num_pages;

        if ($page > 1) $this->_data['page_prev'] = $page - 1;
        if ($page < $num_pages) $this->_data['page_next'] = $page + 1;
        $this->_data['pagination'] = $this->getPagination($page, $num_pages);
        $this->_data['page'] = $page;

        // マップビューじゃない
        if (!$map_list)
        {
            $items = array();
            if ($count > 0)
            {
                $dbParams["pagerFrom"] = ($page - 1) * $page_size + 1;
                $dbParams["pagerTo"] = $pager_from + $page_size;

                // 地域検索
                if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_JYUSYO ||
                    $params['SrhKbn'] == Apm_Config_Search::SRHKBN_KODAWARI)
                {
                    $data = $model->getListForArea($prefCds, $cityCds, $chous, $from, $where, $order, $suborder, $dbParams, $picture_list);
                }
                // 路線検索
                else if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_ENSENEKI)
                {
                    $data = $model->getListForLine($prefCds, $stCds, $from, $where, $order, $suborder, $dbParams, $picture_list);
                }
                // 店舗物件検索
                else if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_TENPOBUKKEN)
                {
                    $data = $model->getListForShop($params['shopCd'], $from, $where, $order, $suborder, $dbParams);
                }

                if (sizeof($data) > 0)
                {
                    $model_conv->dataConverteForBuken($data, $params, false, false);
                }
                $prev = NULL;
                $c = -1;
                foreach ($data as $d)
                {
                    $tatemono = $d['T03_DAIHYO_TATEMONO_CD'];
                    if ($prev != $tatemono)
                    {
                        $c++;
                        $items[] = array();
                    }
                    $d['MAX_CHINRYO_STR'] = (intval($d['MAX_CHINRYO']) / 10000);
                    $d['MIN_CHINRYO_STR'] = (intval($d['MIN_CHINRYO']) / 10000);
                    // OEM判定
                    $OemFlg = ((array_key_exists('OemCd', $params) == true) && (is_null($params['OemCd']) == false) && (is_numeric($params['OemCd']) == true));
                    // 物件画像取得
                    $d['BUKEN_IMAGE'] = Apm_Bukkenitems::GetImageDataMain($d, $OemFlg);
                    $d['FULLGAZOU_ICON'] = Apm_Bukkenitems::GetFullGazouIcon($d['BUKEN_IMAGE']);
                    // キャンペーン取得
                    $heyaCd = $d['T03_HEYA_CD'];
                    $ret = $model->getCamp($heyaCd);
                    if (!empty($ret))
                    {
                        $d['M94_ITEM_ICON'] = $ret['M94_ITEM_ICON'];
                        $d['M94_CAMPAIGN_URL'] = $ret['M94_CAMPAIGN_URL'];
                        $d['M94_CAMPAIGN_NAME'] = $ret['M94_CAMPAIGN_NAME'];
                    }

                    // 住所
                    if ($d['T03_KOUSTU_KIKAN_STR02'] == "－") $d['T03_KOUSTU_KIKAN_STR02'] = '-';
                    if ($d['T03_KOUSTU_KIKAN_STR03'] == "－") $d['T03_KOUSTU_KIKAN_STR03'] = '-';

                    $items[$c][] = $d;
                    $prev = $tatemono;
                }
            }
            $this->_data['list'] = $items;
            $this->_footer_data['ftBukkenList'] = $items;
        }
        // マップビュー
        else
        {
            if (isset($params['daihyoTatemonoCd']))
            {
                $where .= ' ' . $model_common->getDaihyoTatemonoCdWhere($params['daihyoTatemonoCd'], $dbParams);
            }
            else
            {
                $where .= ' ' . $model_common->getLatLngWhere($params, $dbParams);
                $where .= ' ' . $model_common->getExcludeDaihyoTatemonoCdWhere($_SESSION['MAPDATA_' . $params['reqKey']], $dbParams);
            }

            // 地域検索
            if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_JYUSYO || $params['SrhKbn'] == Apm_Config_Search::SRHKBN_KODAWARI)
            {
                // 座標特定
                $maptarget = $this->_data['maptarget'];

                // ターゲット1個だけ→ターゲット検索
                if (isset($params['targetchou_0']) && !isset($params['targetchou_1']))
                {
                    $maptarget = substr($params['targetchou_0'], 0, 2) . '-' . substr($params['targetchou_0'], 0, 5) . '-' . $params['targetchou_0'];
                    $this->_data['maptarget'] = $maptarget;
                }
                else if (isset($params['CityCd']) && sizeof($params['CityCd']) == 1)
                {
                    $maptarget = $params['PrefCd'][0] . '-' . $params['CityCd'][0];
                    $this->_data['maptarget'] = $maptarget;
                }
                // ターゲット1個だけ→ターゲット検索

                if (strlen($maptarget) === 8)
                {
                    $location = $model->getAreaLocation($maptarget);
                    if (isset($location) && !empty($location))
                    {
                        $this->_data['IDO'] = $location[0]['M84_IDO'];
                        $this->_data['KEIDO'] = $location[0]['M84_KEIDO'];
                    }
                }
                else if (strlen($maptarget) === 17)
                {
                    $location = $model->getChoumeiLocation($maptarget);
                    if (isset($location) && !empty($location))
                    {
                        $latlng = $this->toLatLng($location[0]['LOCATION']);
                        $this->_data['IDO'] = $latlng['lat'];
                        $this->_data['KEIDO'] = $latlng['lng'];
                    }
                }

                // データ取得
                $data = $model->getListForAreaMap($prefCds, $cityCds, $chous, $from, $where, $dbParams);
            }
            // 路線検索
            else if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_ENSENEKI)
            {
                // 座標特定
                $maptarget = $this->_data['maptarget'];

                // ターゲット1個だけ→ターゲット検索
                if (isset($params['StCd']) && sizeof($params['StCd']) == 1)
                {
                    $maptarget = $params['PrefCd'][0] . '-' . $params['StCd'][0];
                    $this->_data['maptarget'] = $maptarget;
                }
                // ターゲット1個だけ→ターゲット検索

                $location = $model->getStationLocation($maptarget);
                if (isset($location) && !empty($location))
                {
                    $this->_data['IDO'] = str_replace(',', '', number_format($location[0]['M03_IDO'] * 3600 / 921600, 3));
                    $this->_data['KEIDO'] = str_replace(',', '', number_format($location[0]['M03_KEIDO'] * 3600 / 921600, 3));
                }

                $data = $model->getListForLineMap($prefCds, $stCds, $from, $where, $dbParams);
            }
            // 店舗物件検索
            else if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_TENPOBUKKEN)
            {
                // 座標特定
                $this->_data['IDO'] = str_replace(',', '', number_format($this->_data['Mapping_shop'][0]['M05_TENPO_IDO'] / 1000, 3));
                $this->_data['KEIDO'] = str_replace(',', '', number_format($this->_data['Mapping_shop'][0]['M05_TENPO_KEIDO'] / 1000, 3));
                $data = $model->getListForShopMap($params['shopCd'], $from, $where, $dbParams);
            }

            $ret = $params['daihyoTatemonoCd'] ? $this->convertMapSummary($data) : $this->convertMap($data);

            // $_SESSION['MAPDATA'] = serialize($ret);
            $this->_data['list'] = $ret;
        }
        // マップビュー
    }

    private function makeSeoParams($params)
    {
        $data = array();
        Apm_Seo::generateKodawariBlock($data, $params, array(), 1);
        $this->_data['CrossKodawari'] = $data['CrossKodawari'];

        $data = array();
        Apm_Seo::generateTypeBlock($data, $params, array(), 1);
        $this->_data['CrossType'] = $data['CrossType'];

        // SEO文章は、地域検索・路線検索の場合のみ表示する。
        // 市区町村・駅が複数選択された場合は表示しない。
        // こだわり・建物種別から検索された場合は表示しない。
        // リスト表示のみ対応。(本メソッドはリスト表示の場合のみ呼ばれる)
        if (empty($params['KodawariId']))
        {
            // 地域検索
            if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_JYUSYO ||
                $params['SrhKbn'] == Apm_Config_Search::SRHKBN_KODAWARI)
            {
                // 単一選択の場合のみ対応
                if (sizeof(array_unique($params['CityCd'])) == 1)
                {
                    $pref_cd = substr($params['CityCd'][0], 0, 2);
                    $city_cd = substr($params['CityCd'][0], 2);

                    // 住所説明文マスタ（全国）を取得
                    $model = new Renew_Model_BukkenList();
                    $city_info = $model->getCityInfo($pref_cd, $city_cd);

                    if ($city_info)
                    {
                        $this->_data['seo_text_top'] = $city_info['M01_SEO_TEXT_TOP'];
                        $this->_data['seo_title_bottom_1'] = $city_info['M01_SEO_TITLE_BOTTOM_1'];
                        $this->_data['seo_text_bottom_1'] = $city_info['M01_SEO_TEXT_BOTTOM_1'];
                        $this->_data['seo_title_bottom_2'] = $city_info['M01_SEO_TITLE_BOTTOM_2'];
                        $this->_data['seo_text_bottom_2'] = $city_info['M01_SEO_TEXT_BOTTOM_2'];
                    }
                }
            }
            // 路線検索
            else if ($params['SrhKbn'] == Apm_Config_Search::SRHKBN_ENSENEKI)
            {
                // 単一選択の場合のみ対応
                if (sizeof(array_unique($params['StCd'])) == 1)
                {
                    $station_cd = $params['StCd'][0];

                    // 駅マスタを取得
                    $model = new Renew_Model_BukkenList();
                    $station_info = $model->getStationInfo($station_cd);

                    if ($station_info)
                    {
                        $this->_data['seo_text_top'] = $station_info['M03_SEO_TEXT_TOP'];
                        $this->_data['seo_title_bottom_1'] = $station_info['M03_SEO_TITLE_BOTTOM_1'];
                        $this->_data['seo_text_bottom_1'] = $station_info['M03_SEO_TEXT_BOTTOM_1'];
                        $this->_data['seo_title_bottom_2'] = $station_info['M03_SEO_TITLE_BOTTOM_2'];
                        $this->_data['seo_text_bottom_2'] = $station_info['M03_SEO_TEXT_BOTTOM_2'];
                    }
                }
            }
        }
    }

    public function getPrefData($code)
    {
        $model = new Search_Model_Selareasearch();
        $c = substr($code, 0, 2);
        $this->_data['PrefInfo'] = $model->getSimpleArea($c);
        $this->_data['PrefName'] = $this->getPrefName($c);
        $this->_data['PrefNameJP'] = $this->getPrefNameJP($c);
        $this->_data['PrefNameJPNoPrefix'] = $this->getPrefNameWithoutPostfix($this->_data['PrefNameJP']);
    }

    private function convertForCustomTag($params)
    {
        $tinryo = array(
            '賃料'
        );
        $madori = array();
        $kouzou = array();
        $pet = array();
        $security = array();
        $bathroom = array();
        foreach ($params as $k => $v)
        {
            if ($v != 'on')
            {
                continue;
            }
            switch ($k)
            {
                case 'tinryo_jouken2':
                    array_push($tinryo, '管理費・共益費込み');
                    break;
                case 'tyusyajyo_komi':
                    array_push($tinryo, '駐車場代込み');
                    break;
                case 'madori10':
                    array_push($madori, 'ワンルーム');
                    break;
                case 'madori11':
                    array_push($madori, '1K');
                    break;
                case 'madori12':
                    array_push($madori, '1DK');
                    break;
                case 'madori14':
                    array_push($madori, '1LDK');
                    break;
                case 'madori21':
                    array_push($madori, '2K');
                    break;
                case 'madori22':
                    array_push($madori, '2DK');
                    break;
                case 'madori24':
                    array_push($madori, '2LDK');
                    break;
                case 'madori31':
                    array_push($madori, '3K');
                    break;
                case 'madori32':
                    array_push($madori, '3DK');
                    break;
                case 'madori34':
                    array_push($madori, '3LDK');
                    break;
                case 'madori41':
                    array_push($madori, '4K');
                    break;
                case 'madori42':
                    array_push($madori, '4DK');
                    break;
                case 'madori44':
                    array_push($madori, '4LDK');
                    break;
                case 'madori51':
                    array_push($madori, '5K以上');
                    break;
                case 'kodawari20':
                    array_push($kouzou, '鉄骨造');
                    break;
                case 'kodawari21':
                    array_push($kouzou, '鉄筋コンクリート造');
                    break;
                case 'kodawari136':
                    array_push($kouzou, '鉄骨鉄筋コンクリート造');
                    break;
                case 'kodawari22':
                    array_push($kouzou, '軽量鉄骨造');
                    break;
                case 'kodawari23':
                    array_push($kouzou, '木造');
                    break;
                case 'kodawari24':
                    array_push($kouzou, 'その他');
                    break;
                case 'kodawari10':
                    array_push($pet, 'ペット相談可');
                    break;
                case 'kodawari65':
                    array_push($bathroom, 'バス・トイレ別');
                    break;
                case 'kodawari75':
                    array_push($security, 'TVインターフォン');
                    break;
                case 'kodawari33':
                    array_push($security, 'オートロック');
                    break;
                case 'kodawari107':
                    array_push($security, '防犯カメラ');
                    break;
                case 'kodawari34':
                    array_push($security, '24時間緊急対応');
                    break;
                case 'kodawari123':
                    array_push($security, '管理人あり');
                    break;
                case 'kodawari124':
                    array_push($security, 'ディンプルキー');
                    break;
            }
        }
        $years = '';
        switch ($params['built'])
        {
            case NULL:
            case '0':
                $years = '';
                break;
            case '1':
                $years = '新築';
                break;
            default:
                $years = $params['built'] . '年以内';
                break;
        }

        $tinryo1 = NULL;
        if ($params['tinryo1'] !== null && $params['tinryo1'] !== '' && $params['tinryo1'] !== '0')
        {
            $tinryo1 = $params['tinryo1'] / 10000;
        }
        else
        {
            $tinryo1 = '下限なし';
        }
        $tinryo2 = NULL;
        if ($params['tinryo2'] !== null && $params['tinryo2'] !== '' && $params['tinryo2'] != '9999999')
        {
            $tinryo2 = $params['tinryo2'] / 10000;
        }
        else
        {
            $tinryo2 = '上限なし';
        }

        $this->_footer_data['ftData'] = array(
            tinryo1 => $tinryo1,
            tinryo2 => $tinryo2,
            tinryo => join('_', $tinryo),
            madori => join('_', $madori),
            years => $years,
            kouzou => join('_', $kouzou),
            pet => join('_', $pet),
            security => join('_', $security),
            bathroom => join('_', $bathroom)
        );
    }
    // 地域条件追加・変更データ準備
    private function makeCityModalData($params)
    {
        $cityparams = array();
        $cityparams['PrefCd'][] = $params['PrefCd'][0];
        $data = array();

        $model = new Search_Model_Selsikucyoson();

        $data['selcity'] = $model->getShikucyosonData($cityparams);

        $model->convertShikucyosonData($data, '1');
        $this->_data['Mapping_city_modal'] = $data['Mapping'];
    }

    // 路線条件追加・変更データ準備
    private function makeRosenModalData($params)
    {
        $area_code = substr($params['PrefCd'][0], 0, 2);
        $model = new Search_Model_Selensen();
        $ensenparams = array();
        $ensenparams['PrefCd'][] = $area_code;

        $data = array();
        $data["selensen"] = $model->getEnsenDataByMulti($ensenparams);
        $model->convertEnsenDataByMulti($data);

        $this->_data['Pref_ensen'] = $data["Mapping"];

        // 駅
        $ekimodel = new Search_Model_Seleki();
        $ekiparams = array();
        $ekiparams['PrefCd'][] = $area_code;
        $ekiparams['RailCd'] = $params['RailCd'];
        $ekiparams['listPage'] = true;
        $ekidata = array();
        $ekidata["seleki"] = $ekimodel->getEkiData($ekiparams);
        $ekimodel->convertEkiData($ekidata);
        $this->_data['Pref_eki'] = $ekidata["Mapping"];
        // 駅
    }

    // マップコンバートメソッド
    private function convertMap($data)
    {
        $ret = array();
        foreach ($data as $d)
        {

            // if($d['T03_ANNAI_MAP_USE_FLAG'] !== 1 && $d['T03_ANNAI_MAP_USE_FLAG'] !== '1')
            // continue;

            // $d['BUKEN_IMAGE'] = Apm_Bukkenitems::GetImageDataMain($d,false);

            $ret[] = array(
                'y' => $d['T03_IDO'] * 3600,
                // 'img2' => 'http://img.apamanshop.com/'.$d['BUKEN_IMAGE']['01'][0]['PATH'],
                // 'name' => ($d['T03_TATEMONO_NAME_KOUKAI'] == '1' ? $d['T03_TATEMONO_NAME'] :
                // $d['T03_JYUUSHO_TEXT']),
                'x' => $d['T03_KEIDO'] * 3600,
                // 'type' => $d['T03_TATEMONO_TYPE'],
                // 'rooms' => $d['MIN_MADORI'].'～'.$d['MAX_MADORI'],
                // 'rent1' => $d['MIN_CHINRYO']/10000,
                // 'rent2' => $d['MAX_CHINRYO']/10000,
                // 'floor' => $d['T03_KAIDATE'],
                // 'article' => $d['BUKEN_COUNT'],
                'id' => $d['T03_DAIHYO_TATEMONO_CD']
            );
        }

        return $ret;
    }

    // マップコンバートメソッド
    private function convertMapSummary($data)
    {
        $ret = array();
        foreach ($data as $d)
        {

            // if($d['T03_ANNAI_MAP_USE_FLAG'] !== 1 && $d['T03_ANNAI_MAP_USE_FLAG'] !== '1')
            // continue;

            $d['BUKEN_IMAGE'] = Apm_Bukkenitems::GetImageDataMain($d, false);

            $ret[] = array(
                'y' => $d['T03_IDO'] * 3600,
                'img2' => 'http://img.apamanshop.com/' . $d['BUKEN_IMAGE']['01'][0]['PATH'],
                'name' => ($d['T03_TATEMONO_NAME_KOUKAI'] == '1' ? $d['T03_TATEMONO_NAME'] : $d['T03_JYUUSHO_TEXT']),
                'x' => $d['T03_KEIDO'] * 3600,
                'type' => $d['T03_TATEMONO_TYPE'],
                'rooms' => $d['MIN_MADORI'] . '～' . $d['MAX_MADORI'],
                'rent1' => $d['MIN_CHINRYO'] / 10000,
                'rent2' => $d['MAX_CHINRYO'] / 10000,
                'floor' => $d['T03_KAIDATE'],
                'article' => $d['BUKEN_COUNT'],
                'id' => $d['T03_DAIHYO_TATEMONO_CD']
            );
        }

        return $ret;
    }

    public function getmap($params)
    {
        $this->getBukkenList($params);
        $reqKey = $this->storeIds($params['reqKey'], $this->_data['list']);

        $ret = $this->tojson($this->_data['list'], $reqKey);
        echo $ret;
        exit();
    }

    private function storeIds($reqKey, $bukkenList)
    {
        $reqKey = $reqKey ? $reqKey : $this->uuidv4();
        $stored = $_SESSION['MAPDATA_' . $reqKey] ? $_SESSION['MAPDATA_' . $reqKey] : [];
        $thisreq = array_map(function ($val)
        {
            return $val['id'];
        }, $this->_data['list']);
        $_SESSION['MAPDATA_' . $reqKey] = array_merge($stored, $thisreq);
        return $reqKey;
    }

    private function uuidv4()
    {
        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
    }

    private function tojson($arrList, $reqKey)
    {
        $ret = array();

        foreach ($arrList as $arr)
        {
            foreach ($arr as $key => $value)
            {
                if (is_array($value))
                { // Custom handling for arrays
                    if ($is_list)
                        $parts[] = tojson($value); /* :RECURSION: */
                    else $parts[] = '"' . $key . '":' . tojson($value); /* :RECURSION: */
                }
                else
                {
                    $str = '';
                    if (!$is_list) $str = '"' . $key . '":';

                    // Custom handling for multiple data types
                    // if(is_numeric($value)) $str .= $value; //Numbers
                    if ($value === false)
                        $str .= 'false'; // The booleans
                    elseif ($value === true)
                        $str .= 'true';
                    else $str .= '"' . addslashes($value) . '"'; // All other things
                                                                 // :TODO: Is there any more
                                                                 // datatype we should be in the
                                                                 // lookout for? (Object?)

                    $parts[] = $str;
                }
            }
            $ret[] = '{' . implode(',', $parts) . '}';
        }

        $val = '[' . implode(',', $ret) . ']'; // Return numerical JSON
        return '{' . ($reqKey ? '"reqKey":"' . $reqKey . '",' : '') . '"items":' . $val . '}'; // Return
                                                                                                   // associative
                                                                                                   // JSON
    }
    // POINT (LONGITUDE LATITUDE) 形式文字列を { lng: , lat: } に変換する
    private function toLatLng($wkt)
    {
        $s = strpos($wkt, '(') + 1;
        $arr = explode(' ', substr($wkt, $s, strpos($wkt, ')') - $s));
        return array(
            'lng' => $arr[0] * 3600,
            'lat' => $arr[1] * 3600
        );
    }

    /**
     * SEO対策用のmetaタグに配置する文章を設定
     */
    protected function setSeoMeta()
    {
        $params = $this->getParameters();

        $k = " 賃貸";
        if ($params['syubetu1'])
        {
            $t = "%sのアパートを探す 【アパマンショップ】";
            $des = "%sのアパートを探す";
            if ($params['syubetu2'] || $params['syubetu3'] || $params['syubetu4'] || $params['syubetu5'])
            {
                $t = "%sの賃貸物件を探す 【アパマンショップ】";
                $des = "%sの賃貸物件を探す";
            }
        }
        else if ($params['syubetu2'])
        {
            $t = "%sのマンションを探す 【アパマンショップ】";
            $des = "%sのマンションを探す";
            if ($params['syubetu1'] || $params['syubetu3'] || $params['syubetu4'] || $params['syubetu5'])
            {
                $t = "%sの賃貸物件を探す 【アパマンショップ】";
                $des = "%sの賃貸物件を探す";
            }
        }
        else if ($params['syubetu3'])
        {
            $t = "%sの戸建て・テラスハウスを探す 【アパマンショップ】";
            $des = "%sの戸建て・テラスハウスを探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、";
            if ($params['syubetu1'] || $params['syubetu2'] || $params['syubetu4'] || $params['syubetu5'])
            {
                $t = "%sの賃貸物件を探す 【アパマンショップ】";
                $des = "%sの賃貸物件を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、";
            }
        }
        else if ($params['syubetu4'])
        {
            $t = "%sの貸店舗・賃貸事務所を探す 【アパマンショップ】";
            $des = "%sの貸店舗・賃貸事務所を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、";
            if ($params['syubetu1'] || $params['syubetu2'] || $params['syubetu3'] || $params['syubetu5'])
            {
                $t = "%sの賃貸物件を探す 【アパマンショップ】";
                $des = "%sの賃貸物件を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、";
            }
        }
        else if ($params['syubetu5'])
        {
            $t = "%sの駐車場を探す 【アパマンショップ】";
            $des = "%sの駐車場を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、";
            if ($params['syubetu1'] || $params['syubetu2'] || $params['syubetu3'] || $params['syubetu4'])
            {
                $t = "%sの賃貸物件を探す 【アパマンショップ】";
                $des = "%sの賃貸物件を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、";
            }
        }
        else if ($params['KodawariId'])
        {
            $id = $params['KodawariId'];
            $d1 = Apm_Config_Search::$KODAWARI_ID_STR_LIST[$id];
            $d2 = $d1;
            $t = "%sで" . $d2 . "の賃貸物件を探す 【アパマンショップ】";
            $des = "%sで" . $d2 . "の賃貸物件を探す";
        }
        else
        {
            $t = "%sの賃貸物件を探す 【アパマンショップ】";
            $des = "%sの部屋を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、";

            // 町名まで絞り込んでいる場合
            if ($this->_data['Mapping_city'][0]['CHOU'])
            {
                $t = "%s%sの賃貸物件を探す 【アパマンショップ】";
                $des = "%s%sの部屋を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、";
            }
        }

        if ($params['page'] > 1)
        {
            $t = $params['page'] . 'ページ目 ' . $t;
        }

        if ($t)
        {
            if (array_key_exists('Mapping_eki', $this->_data))
            {
                $d = $this->_data['Mapping_eki'][0]['M03_EKI_NAME'];
                $title = sprintf($t, $d . '駅');

                $description = sprintf($des, $d . '駅');
                $keywords = $d . '駅 賃貸,';
            }
            else if (array_key_exists('Mapping_city', $this->_data))
            {
                $d = $this->_data['Mapping_city'][0]['M01_SHIKUCHOUSON'];

                // 町名まで絞り込んでいる場合
                if ($this->_data['Mapping_city'][0]['CHOU'])
                {
                    $d2 = $this->_data['Mapping_city'][0]['CHOU'][0]["M01_CHOUMEI"];
                    $title = sprintf($t, $d, $d2);
                    $description = sprintf($des, $d, $d2);
                    $keywords = $d . $d2 . $k . ',';
                }
                else
                {
                    $title = sprintf($t, $d);
                    $description = sprintf($des, $d);
                    $keywords = $d . $k . ',';
                }
            }
            else if (array_key_exists('Mapping_ensen', $this->_data))
            {
                $d = $this->_data['Mapping_ensen'][0]['M03_ENSEN_NAME'];
                $title = sprintf($t, $d);

                $description = sprintf($des, $d);
                $keywords = $d . ',';
            }
            else if (array_key_exists('Mapping_shop', $this->_data))
            {
                $d = $this->_data['Mapping_shop'][0]['M05_TENPO_NAME'];
                $title = sprintf($t, $d);

                $description = sprintf($des, $d);
                $keywords = $d . ',';
            }
        }

        $this->_meta_title = $title;
        $this->_meta_description = $description;
        $this->_meta_keywords = $keywords;
    }

}
?>
